package com.talent.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.talent.common.PageConstants;
import com.talent.dao.TrainDetailMapper;
import com.talent.page.Page;
import com.talent.pojo.Schedule;
import com.talent.pojo.TrainDetail;
import com.talent.pojo.User;
import com.talent.service.TrainDetailService;
import com.talent.vo.TrainDetailVo;
import com.talent.vo.TrainPlanVo;
@Service
public class TrainDetailServiceImpl implements TrainDetailService{
	@Autowired
	private TrainDetailMapper trainDetailMapper;

	@Override
	public List<TrainDetailVo> selectVoByTrainPlanKey(Integer id) {
		return trainDetailMapper.selectVoByTrainPlanKey(id);
	}

	@Override
	public Page<TrainDetailVo> selectTrainDetailPage(TrainDetailVo trainDetail,User user, int currentPage) {
		Page<TrainDetailVo> page = new Page<>(currentPage, PageConstants.PAGESIZE);
        List<TrainDetailVo> trainDetailList = trainDetailMapper.selectTrainDetailPage(trainDetail,user, page);
        page.setResultList(trainDetailList);
        return page;
	}

	@Override
	public TrainDetailVo selectVoByPrimaryKey(Integer id) {
		return trainDetailMapper.selectVoByPrimaryKey(id);
	}

	@Override
	public void add(int latestTrainPlanId, List<Schedule> schedules) {
		for(int i = 0; i<schedules.size(); i++){
			TrainDetail trainDetail = new TrainDetail();
			trainDetail.setScheduleId(schedules.get(i).getId());
			trainDetail.setTrainplanId(latestTrainPlanId);
			trainDetailMapper.insert(trainDetail);
		}
	}

	@Override
	public void deleteByIds(List<TrainDetailVo> tds) {
		for(int i = 0; i<tds.size();i++){
			trainDetailMapper.deleteByPrimaryKey(tds.get(i).getId());
		}
	}
}
